package com.api.weavernorth.attend;

import com.weavernorth.attendance.AttendUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weaver.common.DateUtil;
import weaver.general.BaseBean;
import weaver.general.Util;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;


/**
 * @program: ecology_erdos
 * @description:
 * @author: zm
 * @create: 2019-11-05 10:57
 **/
@Path("/weavernorth/attend")
public class AttendLeave extends HttpServlet {
    public static Log log = LogFactory.getLog(AttendLeave.class.getName());

    @GET
    @Path("/leaveDeduct")
    @Produces(MediaType.TEXT_PLAIN)
    public String leaveDeduct(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        BaseBean bb = new BaseBean();

       // String strId=Util.null2String(request.getParameter("ids"));
       // bb.writeLog("进入扣假方法开始"+strId);
        bb.writeLog("进入扣假方法开始");
        //调用扣假方法
        AttendUtil attendUtil = new AttendUtil();
       // attendUtil.leaveDeduct(strId);
        attendUtil.leaveDeduct();
        //  bb.writeLog("进入扣假方法结束");
        return "0";
    }

    @GET
    @Path("/checkDate")
    @Produces(MediaType.TEXT_PLAIN)
    public String checkDate(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        //当前日期
        String strCurrent = DateUtil.getCurrentDate();
        //选择的日期
        String strDateValue = Util.null2String(request.getParameter("dateValue"));
        //当前日期向后30天
        String strUpDay = DateUtil.addDate(strCurrent, 30);
        log.info("向后30天:" + strUpDay);
        //当前日期向前30天
        String strDownDay = DateUtil.addDate(strCurrent, -30);
        log.info("向前30天:" + strDownDay);
        if (strDateValue.compareTo(strDownDay) >= 0 && strDateValue.compareTo(strUpDay) <= 0) {
            return "0";
        }

        return "1";
    }
}
